<?php

class MDOperatorsDraw
{

public static $instance; 

public static function getInstance()
	{
		//echo "<div id=register-box>";
        if(self::$instance==null)
		  self::$instance=new MDOperatorsDraw();
	//   echo "</div>";	  
		return  self::$instance;
	   
    
    }	

function DrawTable($title,$table,$campos)//obligatorio ID como campo inicial
    {
 
 
     $qu="select ";
    $i = 0;
    $i = 0;
    foreach($campos as $id=>$valor)
    {
    $qu=$qu."$id,";


    }
    $qu=substr($qu,0,strlen($qu)-1);
    $qu=$qu." from "."$table";
    
     echo "<div id='content_area_user_title'>";
    echo "<h2> $title</h2>";
    echo "</div>";


    echo	"<form>";						
    echo "<form id='filter-form'>Filtrar operador: <input name='filter' id='filter' value='' maxlength='30' size='30' type='text'></form><br>";
    echo "</form>";
   
    echo "<div class='usersettings_statistics'>"; 
 


    echo "<table class='food_planner'>";
    
    
    echo "<thead>";
    echo "<tr>";    
     foreach($campos as $id=>$valor){
  
    echo "<th>$valor</th>";
    
    }
    
    echo "<th>Paquetes</th>";
    echo "<th>Tours</th>";
    
    echo "</tr>";
     
    
    echo "<tbody><tr style='display: table-row;'>";

     //echo "<table> <tbody>";


    echo "<tr class='odd'>";
 
    
    // $qu="select*from $table";
    $table=CModelo::getInstance()->getData($qu);
//var_dump($table);
    $cont=0;
    
    $ruta=CConfig::getInstance()->rutalocal;
    
    
    foreach($table as $campo => $valor)
    { 



$cont=$cont+1;
if($cont%2){




echo "<tr class='odd'>";
$i="";$cont=0;
foreach($valor as $id=>$val)
{ if($cont==0){$i=$val;}
  if($cont==1){$n=$val;$n=base64_encode($n);}
  echo "<td>$val</td>";$cont=$cont+1;
}
/*---------------------------------------------------------------------------*/
// las referencias debbden de ser modificadas deacuerdo al directorio
//
/*---------------------------------------------------------------------------*/


$query = "select count(*) from pack where OFICINAS_idOfi in (select idOfi from oficinas where OPERADOR_idOpe=$i)";

    $result = CModelo::getInstance()->getData($query);
    foreach($result as $r=>$c){ 
        $table = $c;
        foreach($table as $r2 => $c2){
            $cuentaPack1 = $c2;
        }
    }
    
$query1 = "select count(*) from pack_has_tour where DefaultTourPack='0' AND (pack_idPack IN (select idPack from pack where OFICINAS_idOfi in (select idOfi from oficinas where OPERADOR_idOpe=$i)))";

    $result1 = CModelo::getInstance()->getData($query1);
    foreach($result1 as $r3=>$c3){ 
        $table3 = $c;
        foreach($table3 as $r4 => $c5){
            $cuentaTour1 = $c5;
        }
    }
    

echo "<td><a href='/viventura/MDTour/index.php?idOpe=$i&nval=$n'>$cuentaPack1</a> </td>";
echo "<td><a href='/viventura/MDTour/MDTourGeneral/index.php?idOpe=$i&nval=$n'>$cuentaTour1</a> </td>";
echo "<td> <input type='button' onClick=\"parent.location='../MDOperator/MDOperatorServicio/CResumeServices.php?codigo=$i'\" value='Ver servicios'>  </td>";
echo "<td> <a href='$ruta/MDOperatorGeneral/COperatorEdit.php?codigo=$i&default=0'> <img src='../MDTour/images/edit.png' width='32' title='Editar operador $i'/></a> </td>";
echo "<td><a href='php?codigo=$i'>Eliminar</a> </td>";
echo "<td> <input type=button onClick=\"parent.location='/viventura/MDtour/index.php?idOpe=$i'\" value='Crear tour'>  </td>";
echo "</tr>";
}


else
{
$url="asf";
echo "<tr class='even'> ";
$i2="";$cont2=0;
foreach($valor as $id => $val)
{ if($cont2==0){$i2=$val;}
  if($cont2==1){$n2=$val;$n2=base64_encode($n2);}
  echo "<td>$val </td>";$cont2=$cont2+1;
}

$query = "select count(*) from pack where OFICINAS_idOfi in (select idOfi from oficinas where OPERADOR_idOpe=$i2)";

    $result = CModelo::getInstance()->getData($query);
    foreach($result as $r=>$c){ 
        $table = $c;
        foreach($table as $r2 => $c2){
            $cuentaPack2 = $c2;
        }
    }
    
$query1 = "select count(*) from pack_has_tour where DefaultTourPack='0' AND (pack_idPack IN (select idPack from pack where OFICINAS_idOfi in (select idOfi from oficinas where OPERADOR_idOpe=$i2)))";

    $result2 = CModelo::getInstance()->getData($query1);
    foreach($result2 as $r3=>$c3){ 
        $table3 = $c3;
        foreach($table3 as $r4 => $c4){
            $cuentaTour2 = $c4;
        }
    }
     
    
echo "<td><a href='/viventura/MDTour/index.php?idOpe=$i2&nval=$n2'>$cuentaPack2</a> </td>";
echo "<td><a href='/viventura/MDTour/MDTourGeneral/index.php?idOpe=$i2&nval=$n2'>$cuentaTour2</a> </td>";
echo "<td> <input type='button' onClick=\"parent.location='../MDOperator/MDOperatorServicio/CResumeServices.php?codigo=$i'\" value='Ver servicios'>  </td>";
echo "<td> <a href='$ruta/MDOperatorGeneral/COperatorEdit.php?codigo=$i2&default=0'> <img src='../MDTour/images/edit.png' width='32' title='Editar operador $i'/></a> </td>";
echo "<td><a href='/edson1/modificar.php?codigo=$i2'>Eliminar</a> </td>";
echo "<td> <input type=button onClick=\"parent.location='/viventura/MDtour/index.php?idOpe=$i2'\" value='Crear tour'>  </td>";
echo "</tr>";
}

}
echo "</td></tr></tbody></table><br><br>";


echo "</div>";

} 



}
?>